<template>
  <el-container class="main_con" style="padding-bottom: 0px">
    <ufrom @submit="saveData" ref="ufrom">
        <el-form size="medium" label-width="100px" ref="itemForm" :model="obj.configuration">
          <div class="setting_body_item">
            <div class="header">会员中心设置</div>
            <div class="conetnt edit_con">
              <div class="edit_content">
                <el-form-item>
                  <span slot="label">是否开启</span>
                  <el-radio-group v-model="obj.configuration.is_open">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="会员价">
                  <el-radio-group v-model="obj.configuration.is_price">
                    <el-radio :label="1">仅会员可见</el-radio>
                    <el-radio :label="0">所有用户可见</el-radio>
                  </el-radio-group>
                </el-form-item>
              </div>
            </div>
          </div>
        </el-form>
    </ufrom>
  </el-container>
</template>

<script>
import {addSiteConfig, getSiteConfig, editSiteConfig} from '@/api/mall/setting';

export default {
  data() {
    return {
      isLoading: false,
      obj: {
        type: 'memberLevel',
        configuration: {
          is_open: 0,
          is_price: 0
        }
      }
    };
  },
  created() {
    this.getData(this.obj.type);
  },
  methods: {
    // 保存 或 修改
    saveData() {
      if (this.obj.update_time) {
        editSiteConfig(this.obj)
          .then(res => {
           this.$refs.ufrom.init();
            this.getData(this.obj.type);
          })
          .catch(e => {
           this.$refs.ufrom.init();
          });
      } else {
        addSiteConfig(this.obj)
          .then(res => {
           this.$refs.ufrom.init();
            this.getData(this.obj.type);
          })
          .catch(e => {
            this.$refs.ufrom.init();
          });
      }
    },
    getData(type) {
      this.isLoading = true;
      getSiteConfig(type)
        .then(res => {
          this.obj = res.msg;

          this.isLoading = false;
        })
        .catch(e => {
          this.isLoading = false;
        });
    }
  }
};
</script>
